﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;

namespace zielonka.co.uk.extensions.system.data
{
    // Description: Converts a DataRow into a Hashtable.
    /*
        Hashtable ht = myDataRow.ToHashTable();
    */

    public static partial class DataRowExtensions
    {
        /// <summary>
        /// Converts a DataRow object into a Hashtable object, 
        /// where the key is the ColumnName and the value is the row value.
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        public static Hashtable ToHashTable(this DataRow dr)
        {
            Hashtable htReturn = new Hashtable(dr.ItemArray.Length);
            foreach (DataColumn dc in dr.Table.Columns)
                htReturn.Add(dc.ColumnName, dr[dc.ColumnName]);

            return htReturn;
        }
    }
}
